//
//  YBEarnDetailWithdrawalTimesTableViewCell.m
//  Nectar
//
//  Created by famer on 2023/11/11.
//  Copyright © 2023 asance. All rights reserved.
//

#import "YBEarnDetailWithdrawalTimesTableViewCell.h"

@implementation YBEarnDetailWithdrawalTimesTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        
        self.contentView.backgroundColor = kThemeBackground;
        
        _bgView = [[UIView alloc]initWithFrame:CGRectZero];
        _bgView.clipsToBounds = YES;
        _bgView.layer.cornerRadius = 10;
        _bgView.backgroundColor = kWhiteColor;
        [self.contentView addSubview:_bgView];
        
        _dateLabel = [[UILabel alloc] init];
        _dateLabel.font = [UIFont systemFontOfSize:12];
        _dateLabel.text = @"Date";
        _dateLabel.textColor = [UIColor hexColor:@"84828C"];
        _dateLabel.textAlignment = NSTextAlignmentLeft;
        _dateLabel.numberOfLines = 0;
        _dateLabel.lineBreakMode = NSLineBreakByWordWrapping;
        [_bgView addSubview:_dateLabel];
        
        _dateValueLabel = [[UILabel alloc] init];
        _dateValueLabel.text = @"*";
        _dateValueLabel.font = [UIFont systemFontOfSize:14];
        _dateValueLabel.textColor = kThemeBlackColor;
        _dateValueLabel.textAlignment = NSTextAlignmentRight;
        _dateValueLabel.numberOfLines = 0;
        _dateValueLabel.lineBreakMode = NSLineBreakByWordWrapping;
        [_bgView addSubview:_dateValueLabel];
        
        _withdrawalAmountLabel = [[UILabel alloc] init];
        _withdrawalAmountLabel.text = @"Withdrawal Amount";
        _withdrawalAmountLabel.font = [UIFont systemFontOfSize:12];
        _withdrawalAmountLabel.textColor = [UIColor hexColor:@"84828C"];
        _withdrawalAmountLabel.textAlignment = NSTextAlignmentLeft;
        _withdrawalAmountLabel.numberOfLines = 0;
        _withdrawalAmountLabel.lineBreakMode = NSLineBreakByWordWrapping;
        [_bgView addSubview:_withdrawalAmountLabel];
        
        _withdrawalAmountValueLabel = [[UILabel alloc] init];
        _withdrawalAmountValueLabel.text = @"*";
        _withdrawalAmountValueLabel.font = [UIFont boldSystemFontOfSize:14];
        _withdrawalAmountValueLabel.textColor = kThemeBlackColor;
        _withdrawalAmountValueLabel.textAlignment = NSTextAlignmentRight;
        _withdrawalAmountValueLabel.numberOfLines = 0;
        _withdrawalAmountValueLabel.lineBreakMode = NSLineBreakByWordWrapping;
        [_bgView addSubview:_withdrawalAmountValueLabel];
    }
    return self;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
    CGFloat width = self.contentView.size.width;
    CGFloat height = self.contentView.size.height;
    CGFloat leftMargin = 12;
    CGFloat bgWidth = width-leftMargin*2;
    CGFloat rowWidth = bgWidth-leftMargin*2;
    
    
    self.bgView.frame = CGRectMake(leftMargin, 12, bgWidth, 0);
    
    CGSize dateLabelSize = [self.dateLabel textBoundingSizeWithMaxSize:CGSizeMake(rowWidth, 500)];
    self.dateLabel.frame = CGRectMake(leftMargin,
                                      14,
                                      dateLabelSize.width,
                                      dateLabelSize.height);
    
    CGSize dateValueLabelSize = [self.dateValueLabel textBoundingSizeWithMaxSize:CGSizeMake(rowWidth, 500)];
    self.dateValueLabel.frame = CGRectMake(self.bgView.width-leftMargin-dateValueLabelSize.width,
                                           leftMargin,
                                           dateValueLabelSize.width,
                                           dateValueLabelSize.height);
    
    self.dateLabel.centerY = self.dateValueLabel.centerY;
    
    
    ///
    CGSize withdrawalAmountLabelSize = [self.withdrawalAmountLabel textBoundingSizeWithMaxSize:CGSizeMake(bgWidth, 500)];
    self.withdrawalAmountLabel.frame = CGRectMake(leftMargin,
                                                  self.dateValueLabel.bottom+10,
                                                  rowWidth,
                                                  withdrawalAmountLabelSize.height);
    
    CGSize withdrawalAmountValueLabelSize = [self.withdrawalAmountValueLabel textBoundingSizeWithMaxSize:CGSizeMake(rowWidth, 500)];
    self.withdrawalAmountValueLabel.frame = CGRectMake(leftMargin,
                                                       self.dateValueLabel.bottom+10,
                                                       rowWidth,
                                                       withdrawalAmountValueLabelSize.height);
    
    self.withdrawalAmountLabel.centerY = self.withdrawalAmountValueLabel.centerY;
    
    self.bgView.height= self.withdrawalAmountValueLabel.bottom+14;
}

- (void)setData:(RevDataGetTransferInExtractList *)item{
    
    self.dateValueLabel.text = item.createTime;
    self.withdrawalAmountValueLabel.text = [NSString stringWithFormat:@"%@ USDT", item.amount];
    
    [self setNeedsLayout];
    [self layoutIfNeeded];
}

@end
